package com.TEAM6.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.TEAM6.beans.MemberBean;
import com.TEAM6.dao.MemberDAO;

public class LoginAction implements Action{
	public Forward execute(HttpServletRequest request, HttpServletResponse response) {
		Forward forward = new Forward();
		
		HttpSession session = request.getSession();
		MemberDAO dao = new MemberDAO();
		MemberBean member = new MemberBean();
		member.setId(request.getParameter("id"));
		member.setPassword(request.getParameter("password"));
		boolean check = dao.isMember(member);
		System.out.println(check);
		if(check){
			String name = dao.getMemberName(request.getParameter("id").toString());
			session.setAttribute("id", member.getId());
			session.setAttribute("name", name);
			//session.setAttribute("name", member.getId());
			forward.setPagePath("./main.zzang");
		}else{
			forward.setPagePath("./index.jsp");
		}
		
		forward.setRedirect(true);
		return forward;	
	}
	
}
